package com.hnu.store.service.impl;

import com.hnu.store.entity.Feedback;
import com.hnu.store.mapper.FeedbackMapper;
import com.hnu.store.service.IFeedbackService;
import com.hnu.store.service.ex.ChangeInfoException;
import com.hnu.store.service.ex.InsertException;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FeedbackServiceImpl implements IFeedbackService {

    @Autowired
    public FeedbackMapper feedbackMapper;

    @Override
    public List<Feedback> getAllFeedback(){
        List<Feedback> feedbackList=feedbackMapper.getAllFeedbackList();
        return feedbackList;
    }

    @Override
    public List<Feedback> getFeedbackListByUserid(Integer userid){
        List<Feedback> feedbackList=feedbackMapper.getFeedbackListByuserId(userid);
        return feedbackList;
    }

    @Override
    public Feedback getFeedbackById(Integer feedbackId){
        Feedback feedback=feedbackMapper.getFeedbackById(feedbackId);
        return feedback;
    }

    @Override
    public void addContent(Integer feedbackId, String content){
        if(feedbackMapper.insertFeedbackContent(feedbackId,content)!=1){
            throw new ChangeInfoException("添加回复内容错误");
        }
    }

    @Override
    public void insert(Feedback feedback){
        if (feedbackMapper.insert(feedback)!=1){
            throw new InsertException("插入反馈错误");
        }
    }
}
